<template>
  <div>
    <button @click="onClick">按钮</button>
    <p ref="p">Hello world!</p>
    <my-component ref="my-component"></my-component>
  </div>
</template>

<script>
import MyComponent from './MyComponent.vue'

export default {
  components: {
    MyComponent
  },
  methods: {
    onClick() {
      // 获取 DOM 元素
      const p = this.$refs.p
      console.log(p.innerHTML)

      // 获取组件实例
      const myComponent = this.$refs['my-component']
      console.log(myComponent.msg)
    }
  }
}
</script>
